{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "# Загрузка проверочного файла\n",
        "validation_path = \"/content/Количество исследований за месяц (для проверки).xlsx\"\n",
        "validation_data = pd.read_excel(validation_path)\n",
        "\n",
        "# Посмотрим на структуру данных проверочного файла\n",
        "validation_data.head()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 278
        },
        "id": "blyBh3XPoqMI",
        "outputId": "5dcdce8a-6aee-428f-93dd-6f9c3b71248c"
      },
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "    Год Номер недели  Денс - Кол-во исследований   КТ - Кол-во исследований   \\\n",
              "0  2024            1                       1970.0                     4437.0   \n",
              "1  2024            2                       2089.0                     4506.0   \n",
              "2  2024            3                       1833.0                     4058.0   \n",
              "3  2024            4                       1827.0                     3990.0   \n",
              "4  2024            5                       2196.0                     4765.0   \n",
              "\n",
              "   КТ с КУ 1 зона - Кол-во исследований   \\\n",
              "0                                  508.0   \n",
              "1                                  577.0   \n",
              "2                                  606.0   \n",
              "3                                  635.0   \n",
              "4                                  597.0   \n",
              "\n",
              "   КТ с КУ 2 и более зон - Кол-во исследований   ММГ - Кол-во исследований   \\\n",
              "0                                         541.0                     19061.0   \n",
              "1                                         570.0                     19666.0   \n",
              "2                                         528.0                     17039.0   \n",
              "3                                         567.0                     16623.0   \n",
              "4                                         610.0                     19955.0   \n",
              "\n",
              "   МРТ - Кол-во исследований   МРТ с КУ 1 зона - Кол-во исследований   \\\n",
              "0                      1675.0                                   817.0   \n",
              "1                      1903.0                                   833.0   \n",
              "2                      1748.0                                   806.0   \n",
              "3                      1936.0                                   829.0   \n",
              "4                      1928.0                                   821.0   \n",
              "\n",
              "   МРТ с КУ 2 и более зон - Кол-во исследований   РГ - Кол-во исследований   \\\n",
              "0                                           14.0                    67021.0   \n",
              "1                                           17.0                    70212.0   \n",
              "2                                           14.0                    61990.0   \n",
              "3                                           20.0                    64422.0   \n",
              "4                                           10.0                    71415.0   \n",
              "\n",
              "   ФЛГ - Кол-во исследований   \n",
              "0                     40364.0  \n",
              "1                     38880.0  \n",
              "2                     36616.0  \n",
              "3                     31052.0  \n",
              "4                     38298.0  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-b03c1377-1bc0-40ce-a500-6a7adaf328e5\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Год</th>\n",
              "      <th>Номер недели</th>\n",
              "      <th>Денс - Кол-во исследований</th>\n",
              "      <th>КТ - Кол-во исследований</th>\n",
              "      <th>КТ с КУ 1 зона - Кол-во исследований</th>\n",
              "      <th>КТ с КУ 2 и более зон - Кол-во исследований</th>\n",
              "      <th>ММГ - Кол-во исследований</th>\n",
              "      <th>МРТ - Кол-во исследований</th>\n",
              "      <th>МРТ с КУ 1 зона - Кол-во исследований</th>\n",
              "      <th>МРТ с КУ 2 и более зон - Кол-во исследований</th>\n",
              "      <th>РГ - Кол-во исследований</th>\n",
              "      <th>ФЛГ - Кол-во исследований</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2024</td>\n",
              "      <td>1</td>\n",
              "      <td>1970.0</td>\n",
              "      <td>4437.0</td>\n",
              "      <td>508.0</td>\n",
              "      <td>541.0</td>\n",
              "      <td>19061.0</td>\n",
              "      <td>1675.0</td>\n",
              "      <td>817.0</td>\n",
              "      <td>14.0</td>\n",
              "      <td>67021.0</td>\n",
              "      <td>40364.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2024</td>\n",
              "      <td>2</td>\n",
              "      <td>2089.0</td>\n",
              "      <td>4506.0</td>\n",
              "      <td>577.0</td>\n",
              "      <td>570.0</td>\n",
              "      <td>19666.0</td>\n",
              "      <td>1903.0</td>\n",
              "      <td>833.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>70212.0</td>\n",
              "      <td>38880.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2024</td>\n",
              "      <td>3</td>\n",
              "      <td>1833.0</td>\n",
              "      <td>4058.0</td>\n",
              "      <td>606.0</td>\n",
              "      <td>528.0</td>\n",
              "      <td>17039.0</td>\n",
              "      <td>1748.0</td>\n",
              "      <td>806.0</td>\n",
              "      <td>14.0</td>\n",
              "      <td>61990.0</td>\n",
              "      <td>36616.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>2024</td>\n",
              "      <td>4</td>\n",
              "      <td>1827.0</td>\n",
              "      <td>3990.0</td>\n",
              "      <td>635.0</td>\n",
              "      <td>567.0</td>\n",
              "      <td>16623.0</td>\n",
              "      <td>1936.0</td>\n",
              "      <td>829.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>64422.0</td>\n",
              "      <td>31052.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>2024</td>\n",
              "      <td>5</td>\n",
              "      <td>2196.0</td>\n",
              "      <td>4765.0</td>\n",
              "      <td>597.0</td>\n",
              "      <td>610.0</td>\n",
              "      <td>19955.0</td>\n",
              "      <td>1928.0</td>\n",
              "      <td>821.0</td>\n",
              "      <td>10.0</td>\n",
              "      <td>71415.0</td>\n",
              "      <td>38298.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-b03c1377-1bc0-40ce-a500-6a7adaf328e5')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-b03c1377-1bc0-40ce-a500-6a7adaf328e5 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-b03c1377-1bc0-40ce-a500-6a7adaf328e5');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-d575ef9d-54bb-46cf-b6ad-2bde2a395786\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-d575ef9d-54bb-46cf-b6ad-2bde2a395786')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-d575ef9d-54bb-46cf-b6ad-2bde2a395786 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "dataframe",
              "variable_name": "validation_data",
              "summary": "{\n  \"name\": \"validation_data\",\n  \"rows\": 7,\n  \"fields\": [\n    {\n      \"column\": \"\\u0413\\u043e\\u0434\",\n      \"properties\": {\n        \"dtype\": \"category\",\n        \"num_unique_values\": 2,\n        \"samples\": [\n          \"\\u041a\\u0423\",\n          2024\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u041d\\u043e\\u043c\\u0435\\u0440 \\u043d\\u0435\\u0434\\u0435\\u043b\\u0438\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 6,\n        \"samples\": [\n          1,\n          2\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u0414\\u0435\\u043d\\u0441 - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 160.9425363289643,\n        \"min\": 1827.0,\n        \"max\": 2196.0,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          2089.0,\n          2196.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u041a\\u0422 - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 323.64594853018014,\n        \"min\": 3990.0,\n        \"max\": 4765.0,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          4506.0,\n          4765.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u041a\\u0422 \\u0441 \\u041a\\u0423 1 \\u0437\\u043e\\u043d\\u0430 - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 47.63717036096918,\n        \"min\": 508.0,\n        \"max\": 635.0,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          577.0,\n          597.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u041a\\u0422 \\u0441 \\u041a\\u0423 2 \\u0438 \\u0431\\u043e\\u043b\\u0435\\u0435 \\u0437\\u043e\\u043d - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 31.554714386284658,\n        \"min\": 528.0,\n        \"max\": 610.0,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          570.0,\n          610.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u041c\\u041c\\u0413 - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 1536.5614859158745,\n        \"min\": 16623.0,\n        \"max\": 19955.0,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          19666.0,\n          19955.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u041c\\u0420\\u0422 - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 118.95167085837845,\n        \"min\": 1675.0,\n        \"max\": 1936.0,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          1903.0,\n          1928.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u041c\\u0420\\u0422 \\u0441 \\u041a\\u0423 1 \\u0437\\u043e\\u043d\\u0430 - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 10.59245014149229,\n        \"min\": 806.0,\n        \"max\": 833.0,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          833.0,\n          821.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u041c\\u0420\\u0422 \\u0441 \\u041a\\u0423 2 \\u0438 \\u0431\\u043e\\u043b\\u0435\\u0435 \\u0437\\u043e\\u043d - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 3.7416573867739413,\n        \"min\": 10.0,\n        \"max\": 20.0,\n        \"num_unique_values\": 4,\n        \"samples\": [\n          17.0,\n          10.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u0420\\u0413 - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 3922.8520874486208,\n        \"min\": 61990.0,\n        \"max\": 71415.0,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          70212.0,\n          71415.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"\\u0424\\u041b\\u0413 - \\u041a\\u043e\\u043b-\\u0432\\u043e \\u0438\\u0441\\u0441\\u043b\\u0435\\u0434\\u043e\\u0432\\u0430\\u043d\\u0438\\u0439 \",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 3607.3896379515204,\n        \"min\": 31052.0,\n        \"max\": 40364.0,\n        \"num_unique_values\": 5,\n        \"samples\": [\n          38880.0,\n          38298.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}"
            }
          },
          "metadata": {},
          "execution_count": 11
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "import numpy as np\n",
        "from sklearn.ensemble import RandomForestRegressor\n",
        "from sklearn.model_selection import GridSearchCV\n",
        "import openpyxl"
      ],
      "metadata": {
        "id": "So97j8lWydy6"
      },
      "execution_count": 12,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Чтение данных\n",
        "data_path = \"/content/Количество исследований по неделям (для реализации).xlsx\"\n",
        "template_path = \"/content/Шаблон для заполнения проверки по прогнозу за Февраль.xlsx\"\n",
        "validation_path = \"/content/Количество исследований за месяц (для проверки).xlsx\"\n",
        "\n",
        "data = pd.read_excel(data_path)\n",
        "validation_data = pd.read_excel(validation_path)"
      ],
      "metadata": {
        "id": "8FtxVxTCygui"
      },
      "execution_count": 13,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Преобразование года и номера недели в дату (начиная с понедельника каждой недели)\n",
        "data['Date'] = pd.to_datetime(data['Год'].astype(str) + '-' + data['Номер недели'].astype(str) + '-1', format='%G-%V-%u')"
      ],
      "metadata": {
        "id": "41dOPMY7ykUo"
      },
      "execution_count": 14,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Убираем пропуски\n",
        "data.fillna(0, inplace=True)"
      ],
      "metadata": {
        "id": "cgEo9a-DyxhZ"
      },
      "execution_count": 15,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Создание модели и прогнозирование с подбором гиперпараметров\n",
        "predictions = {}\n",
        "features = np.array(data['Номер недели']).reshape(-1, 1)"
      ],
      "metadata": {
        "id": "8lP_aq3fyxnN"
      },
      "execution_count": 16,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Параметры для подбора\n",
        "param_grid = {\n",
        "    'n_estimators': [50, 100, 200],\n",
        "    'max_depth': [10, 20, None],\n",
        "    'min_samples_split': [2, 5, 10],\n",
        "    'min_samples_leaf': [1, 2, 4]\n",
        "}"
      ],
      "metadata": {
        "id": "x5h4BfcAysBo"
      },
      "execution_count": 17,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "for column in data.columns[2:]:\n",
        "    model = RandomForestRegressor(random_state=42)\n",
        "    target = data[column].values\n",
        "    grid_search = GridSearchCV(model, param_grid, cv=5, n_jobs=-1, verbose=1)\n",
        "    grid_search.fit(features, target)\n",
        "\n",
        "    best_model = grid_search.best_estimator_\n",
        "\n",
        "    # Прогнозируем на февраль (недели 5-8)\n",
        "    february_weeks = np.array([5, 6, 7, 8]).reshape(-1, 1)\n",
        "    predictions[column] = best_model.predict(february_weeks)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "EDuLux5XysEf",
        "outputId": "ce5c0972-7000-47e3-c73a-595617f832fc"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Fitting 5 folds for each of 81 candidates, totalling 405 fits\n",
            "Fitting 5 folds for each of 81 candidates, totalling 405 fits\n",
            "Fitting 5 folds for each of 81 candidates, totalling 405 fits\n",
            "Fitting 5 folds for each of 81 candidates, totalling 405 fits\n",
            "Fitting 5 folds for each of 81 candidates, totalling 405 fits\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Конвертируем прогнозы в DataFrame\n",
        "predictions_df = pd.DataFrame(predictions, index=['Week 5', 'Week 6', 'Week 7', 'Week 8'])"
      ],
      "metadata": {
        "id": "_cebaMydykXL"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Чтение шаблона для заполнения\n",
        "template_wb = openpyxl.load_workbook(template_path)\n",
        "template_ws = template_wb.active"
      ],
      "metadata": {
        "id": "OUao0MEgykZv"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Запись прогнозов в шаблон\n",
        "for row, week in enumerate(predictions_df.index, start=2):  # Начинаем с 2-й строки\n",
        "    for col, column in enumerate(predictions_df.columns, start=2):  # Начинаем с 2-го столбца\n",
        "        template_ws.cell(row=row, column=col).value = predictions_df.at[week, column]"
      ],
      "metadata": {
        "id": "MXCz-Uanykcb"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# Сохранение обновленного шаблона\n",
        "output_path = \"/content/Прогноз_на_Февраль_с_гиперпараметрами.xlsx\"\n",
        "template_wb.save(output_path)"
      ],
      "metadata": {
        "id": "eW_ecFaKyke_"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}